﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_StorageAdd : System.Web.UI.Page
{
    Function f = new Function();
    ZSql zs = new ZSql();
    ZSql info = new ZSql();//添加修改
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblUser.Text = Server.UrlDecode(Request.Cookies["user"].Values["realname"]);//操作人
            lblPatd.Text = f.getModuleidAdd(Request.QueryString["moduid"]);//当前位置
            hidModuid.Value = Request.QueryString["moduid"];//当前位置
            HidGoUrl.Value = Request.UrlReferrer.ToString();
            lblTime.Text = DateTime.Now.ToShortDateString();
            if (!string.IsNullOrEmpty(Request.QueryString["OutStockId"]))//修改操作
            {
                initData();
            }
            else
            {
                lblTime.Text = DateTime.Now.ToShortDateString();//初始化操作时间
            }
        }
    }
    private void initData()//当修改时,初使化数据
    {
        ZSql rs = new ZSql();
        if (!string.IsNullOrEmpty(Request.QueryString["OutStockId"]))
        {
            string sql = "select top 1 * from (select a.*,(select TypeName from SV_Type where a.TypeId=TypeId) as TypeName,(select catalogueName from SV_catalogue where a.ComodBarcode=ComodBarcode) as catalogueName,(select top 1 StaffName from CS_Staff where StaffId=a.maintmen ) as StaffName from SV_OutStock a ) TblOutStock where OutStockId=" + Request.QueryString["OutStockId"].ToString();
            //Response.Write(sql);
            //Response.End();
            rs.Open(sql);
            if (rs.m_table.Rows.Count > 0)
            {

                ComodBarcode.Text = rs.m_table.Rows[0]["ComodBarcode"].ToString();
                catalogueName.Text = rs.m_table.Rows[0]["catalogueName"].ToString();//名称
                ComodBarcode.Text = rs.m_table.Rows[0]["ComodBarcode"].ToString();
                Units.Text = rs.m_table.Rows[0]["Units"].ToString();
                TypeName.Text = rs.m_table.Rows[0]["TypeName"].ToString();//单位
                OutCode.Text = rs.m_table.Rows[0]["OutCode"].ToString();//进库数量
                Remark.Text = rs.m_table.Rows[0]["Remark"].ToString();//备注
                lblTime.Text = rs.m_table.Rows[0]["EditDate"].ToString();//初始化操作时间
                OutNum.Value = rs.m_table.Rows[0]["OutNum"].ToString();
                Prices.Value = rs.m_table.Rows[0]["prices"].ToString();//单价
                TotalMoney.Value = rs.m_table.Rows[0]["TotalMoney"].ToString();//总价
                OutNum.Value = rs.m_table.Rows[0]["OutNum"].ToString();
            }
        }
        rs.Close();
    }

   
    protected void btnAdd_Click(object sender, EventArgs e)//系统提交
    {

        ZSql info = new ZSql();
        string sql = "";
        if (!string.IsNullOrEmpty(Request.QueryString["OutStockId"]))
        {
            sql = "select top 1 * from SV_OutStock where OutStockId=" + Request.QueryString["OutStockId"];

            info.Open(sql);
            info.NextRow();

            info["OutNum"] = OutNum.Value.ToString();//数量
            info["Remark"] = Remark.Text;//备注
            info["Prices"] = Prices.Value.ToString();
            info["TotalMoney"] = TotalMoney.Value.ToString();

            info.Update();
            info.Close();
            Response.Write("<script>alert('操作已成功，请返回！');</script>");//返回页面
            Response.Write("<script>window.location='" + HidGoUrl.Value + "';</script>");//返回页面
        }

    }


    
    /*
    protected void ddlComodBarcode_SelectedIndexChanged(object sender, EventArgs e)
    {
        ZSql rs = new ZSql();
        if (!string.IsNullOrEmpty(ddlComodBarcode.Text))
        {
            string sql = "select top 1 *,(select Units from Units where SV_Catalogue.Units=UnitsId) as  UnitsName from SV_Catalogue where ComodBarcode='" + ddlComodBarcode.SelectedValue.ToString()+"'";
            rs.Open(sql);
            if (rs.m_table.Rows.Count > 0)
            {
                catalogueName.Text = rs.m_table.Rows[0]["catalogueName"].ToString();//名称
                Units.Text = rs.m_table.Rows[0]["UnitsName"].ToString();//单位
                Spec.Text = rs.m_table.Rows[0]["Spec"].ToString();//进库数量
                Remark.Text = rs.m_table.Rows[0]["Remark"].ToString();//备注
                if (rs.m_table.Rows[0]["AuditState"].ToString() == "1") AuditState.Checked = true; else AuditState1.Checked = true;
            }
        }
        rs.Close();
    }*/
}
